using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using SharpCore.Data;
using SharpCore.Utilities;

namespace Dating.DA
{
	public class GeneralBuildPreferenceDA
	{
		#region Fields

		protected string connectionStringName;

		#endregion

		#region Constructors
		public GeneralBuildPreferenceDA()
		{
		}

		public GeneralBuildPreferenceDA(string connectionStringName)
		{
			ValidationUtility.ValidateArgument("connectionStringName", connectionStringName);

			this.connectionStringName = connectionStringName;
		}

		#endregion

		#region Methods

		/// <summary>
		/// Saves a record to the GeneralBuildPreference table.
		/// </summary>
		public  int Insert(GeneralBuildPreference generalBuildPreference)
		{
			ValidationUtility.ValidateArgument("generalBuildPreference", generalBuildPreference);

			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", generalBuildPreference.TenantID),
				new SqlParameter("@ProfileID", generalBuildPreference.ProfileID),
				new SqlParameter("@PreferenceID", generalBuildPreference.PreferenceID)
			};

			generalBuildPreference.GeneralBuildID = Convert.ToInt32(SqlClientUtility.ExecuteScalar(connectionStringName, CommandType.StoredProcedure, "GeneralBuildPreferenceInsert", parameters));
			return generalBuildPreference.GeneralBuildID;
		}

		/// <summary>
		/// Updates a record in the GeneralBuildPreference table.
		/// </summary>
		public  int Update(GeneralBuildPreference generalBuildPreference)
		{
			ValidationUtility.ValidateArgument("generalBuildPreference", generalBuildPreference);

			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@GeneralBuildID", generalBuildPreference.GeneralBuildID),
				new SqlParameter("@TenantID", generalBuildPreference.TenantID),
				new SqlParameter("@ProfileID", generalBuildPreference.ProfileID),
				new SqlParameter("@PreferenceID", generalBuildPreference.PreferenceID)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "GeneralBuildPreferenceUpdate", parameters));
		}

		/// <summary>
		/// Deletes a record from the GeneralBuildPreference table by its primary key.
		/// </summary>
		public  int Delete(int generalBuildID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@GeneralBuildID", generalBuildID)
,				new SqlParameter("@TenantID", tenantID)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "GeneralBuildPreferenceDelete", parameters));
		}

		/// <summary>
		/// Deletes a record from the GeneralBuildPreference table by a foreign key.
		/// </summary>
		public  int DeleteAllByPreferenceID(int preferenceID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@PreferenceID", preferenceID)
,				new SqlParameter("@TenantID", tenantID)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "GeneralBuildPreferenceDeleteAllByPreferenceID", parameters));
		}

		/// <summary>
		/// Deletes a record from the GeneralBuildPreference table by a foreign key.
		/// </summary>
		public  int DeleteAllByProfileID(int profileID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ProfileID", profileID)
,				new SqlParameter("@TenantID", tenantID)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "GeneralBuildPreferenceDeleteAllByProfileID", parameters));
		}

		/// <summary>
		/// Deletes a record from the GeneralBuildPreference table by a foreign key.
		/// </summary>
		public  int DeleteAllByTenantID(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)

			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "GeneralBuildPreferenceDeleteAllByTenantID", parameters));
		}

		/// <summary>
		/// Selects a single record from the GeneralBuildPreference table.
		/// </summary>
		public  GeneralBuildPreference Select(int generalBuildID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@GeneralBuildID", generalBuildID)
,				new SqlParameter("@TenantID", tenantID)
			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "GeneralBuildPreferenceSelect", parameters))
			{
				if (dataReader.Read())
				{
					return MakeGeneralBuildPreference(dataReader);
				}
				else
				{
					return null;
				}
			}
		}

		/// <summary>
		/// Selects all records from the GeneralBuildPreference table.
		/// </summary>
		public  List<GeneralBuildPreference> SelectAll(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)
			};
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "GeneralBuildPreferenceSelectAll", parameters))
			{
				List<GeneralBuildPreference> generalBuildPreferenceList = new List<GeneralBuildPreference>();
				while (dataReader.Read())
				{
					GeneralBuildPreference generalBuildPreference = MakeGeneralBuildPreference(dataReader);
					generalBuildPreferenceList.Add(generalBuildPreference);
				}

				return generalBuildPreferenceList;
			}
		}

		/// <summary>
		/// Selects all records from the GeneralBuildPreference table by a foreign key.
		/// </summary>
		public  List<GeneralBuildPreference> SelectAllByPreferenceID(int preferenceID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@PreferenceID", preferenceID)
,				new SqlParameter("@TenantID", tenantID)
			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "GeneralBuildPreferenceSelectAllByPreferenceID", parameters))
			{
				List<GeneralBuildPreference> generalBuildPreferenceList = new List<GeneralBuildPreference>();
				while (dataReader.Read())
				{
					GeneralBuildPreference generalBuildPreference = MakeGeneralBuildPreference(dataReader);
					generalBuildPreferenceList.Add(generalBuildPreference);
				}

				return generalBuildPreferenceList;
			}
		}

		/// <summary>
		/// Selects all records from the GeneralBuildPreference table by a foreign key.
		/// </summary>
		public  List<GeneralBuildPreference> SelectAllByProfileID(int profileID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ProfileID", profileID)
,				new SqlParameter("@TenantID", tenantID)
			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "GeneralBuildPreferenceSelectAllByProfileID", parameters))
			{
				List<GeneralBuildPreference> generalBuildPreferenceList = new List<GeneralBuildPreference>();
				while (dataReader.Read())
				{
					GeneralBuildPreference generalBuildPreference = MakeGeneralBuildPreference(dataReader);
					generalBuildPreferenceList.Add(generalBuildPreference);
				}

				return generalBuildPreferenceList;
			}
		}

		/// <summary>
		/// Selects all records from the GeneralBuildPreference table by a foreign key.
		/// </summary>
		public  List<GeneralBuildPreference> SelectAllByTenantID(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)

			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "GeneralBuildPreferenceSelectAllByTenantID", parameters))
			{
				List<GeneralBuildPreference> generalBuildPreferenceList = new List<GeneralBuildPreference>();
				while (dataReader.Read())
				{
					GeneralBuildPreference generalBuildPreference = MakeGeneralBuildPreference(dataReader);
					generalBuildPreferenceList.Add(generalBuildPreference);
				}

				return generalBuildPreferenceList;
			}
		}

		/// <summary>
		/// Creates a new instance of the GeneralBuildPreference class and populates it with data from the specified SqlDataReader.
		/// </summary>
		protected  GeneralBuildPreference MakeGeneralBuildPreference(SqlDataReader dataReader)
		{
			GeneralBuildPreference generalBuildPreference = new GeneralBuildPreference();
			generalBuildPreference.GeneralBuildID = SqlClientUtility.GetInt32(dataReader, "GeneralBuildID", 0);
			generalBuildPreference.TenantID = SqlClientUtility.GetInt32(dataReader, "TenantID", 0);
			generalBuildPreference.ProfileID = SqlClientUtility.GetInt32(dataReader, "ProfileID", 0);
			generalBuildPreference.PreferenceID = SqlClientUtility.GetInt32(dataReader, "PreferenceID", 0);

			return generalBuildPreference;
		}

		#endregion
	}
}
